class Solution(object):
    def minPatches(self, nums, n):
        # the first missing partial sum
        miss = 1
        # num of numbers added to array
        added = 0
        # index to iterate number in array
        i = 0
        while miss<=n:
            if i<len(nums) and nums[i]<=miss:
                # if num < miss, enlarge range fomr [0,miss) to [0,miss+num)
                miss+=nums[i]
                i+=1
            else:
                # we can not find miss or any number less than miss, just add miss to array
                miss+=miss
                added+=1
        return added